import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

public class Demo852 {
    public class TcpEchoClient {
        Socket socket =null;
        String serverIP ;
        int port;
        public TcpEchoClient(String serverIP,int port) throws IOException {
            socket = new Socket(serverIP,port);
        }
        public void start(){
            Scanner scannerConsole = new Scanner(System.in);
            try(InputStream inputStream = socket.getInputStream();
                OutputStream outputStream = socket.getOutputStream()){
                while(true) {
                    System.out.print("-> ");
                    String request = scannerConsole.next();
                    PrintStream printStream = new PrintStream(outputStream);
                    printStream.println(request);
                    printStream.flush();
                    Scanner scannerNetwork = new Scanner(inputStream);
                    String respone = scannerNetwork.next();
                    System.out.println(respone);
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        public static void main(String[] args) throws IOException {
            TcpEchoClient tcpEchoClient = new TcpEchoClient("127.0.0.1",9001);
            tcpEchoClient.start();
        }
    }




}
